﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sworm
{
    public sealed class Param
    {
        private readonly object value;

        public Param(string name, object value)
        {
            this.Name = name;
            this.value = value;
        }

        public string Name { get; private set; }

        public object GetConvertedValue(MetadataBuilder metadata)
        {
            if (value == null)
            {
                return DBNull.Value;
            }
            var converter = metadata.GetDefaultToDbConverter(value.GetType());
            if (converter != null)
            {
                return converter(value) ?? DBNull.Value;
            }
            else
            {
                return value;
            }
        }
    }
}
